package com.cjm.one.webmanager.controller.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.system.dto.SysDictDataDto;
import com.cjm.one.model.system.entity.SysDictData;
import com.cjm.one.model.system.entity.SysDictType;
import com.cjm.one.webmanager.service.system.SysDictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "1-系统字典管理")
@RequestMapping("/manager/system/dict")
public class SysDictController {

    @Resource
    private SysDictService sysDictService;

    @PostMapping("/type/findAll")
    @Operation(summary = "查询所有字典的类型")
    public Result<List<SysDictType>> findAll(@RequestBody SysDictDataDto sysDictDataDto){
        return Result.ok(sysDictService.findAll(sysDictDataDto));
    }
    @PostMapping("/type")
    @Operation(summary = "新增字典类型")
    public Result<Boolean> saveDictType(@RequestBody SysDictType sysDictType) {
        return Result.ok(sysDictService.saveDictType(sysDictType));
    }
    @PutMapping("/type")
    @Operation(summary = "修改字典类型")
    public Result<Boolean> updateSysDictTypeById(@RequestBody SysDictType sysDictType) {
        return Result.ok(sysDictService.updateSysDictTypeById(sysDictType));
    }
    @DeleteMapping("/type")
    @Operation(summary = "删除字典类型")
    public Result<Boolean> removeSysDictTypeById(@RequestBody SysDictDataDto sysDictDataDto) {
        return Result.ok(sysDictService.removeSysDictTypeById(sysDictDataDto));
    }

    @GetMapping("/type/{id}")
    @Operation(summary = "根据id查询字典类型")
    public Result<SysDictType> findById(@PathVariable("id") Long id) {
        return Result.ok(sysDictService.findById(id));
    }


//    =======================================================================================================

    @PostMapping("/data/list")
    @Operation(summary = "分页字典数据列表")
    public Result<Page<SysDictData>>  list(@RequestBody SysDictDataDto sysDictDataDto){
        return Result.ok(sysDictService.list(sysDictDataDto));
    }
    @PostMapping("/data")
    @Operation(summary = "保存字典数据")
    public Result<Boolean> save(@RequestBody SysDictData sysDictData) {
        return Result.ok(sysDictService.save(sysDictData));
    }
    @PutMapping("/data")
    @Operation(summary = "修改字典数据")
    public Result<Boolean> update(@RequestBody SysDictData sysDictData) {
        return Result.ok(sysDictService.updateById(sysDictData));
    }
    @DeleteMapping("/data/{id}")
    @Operation(summary = "删除字典数据")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(sysDictService.removeById(id));
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询字典数据")
    public Result<SysDictData> getById(@PathVariable Long id) {
        return Result.ok(sysDictService.getById(id));
    }

}
